import React, { Component } from 'react'
import { connect } from 'react-redux'
import Axios from "axios"
//引入组件
import Index from "./components/Index"
export class App extends Component {
  componentWillMount() {
    this.props.getList()
  }
  render() {
    return (
      <div className="app">
        {/* 调用组件 */}
        <Index {...this.props} />
      </div>
    )
  }

}

const mapStateToProps = (state) => {
  return {
    ...state
  }
}

const mapDispatchToProps = (dispatch) => {
  return {
    // 数据库存数据
    getList() {
      dispatch(() => {
        Axios.get("/get/list").then(res => {
          dispatch({ type: "SET_LIST", data: res.data.data })
        })
      })
    },
    setList(data) {
      dispatch({ type: "SET_LIST", data: data })
    }
  }
}

export default connect(mapStateToProps, mapDispatchToProps)(App)
